package com.esri.core.internal.tasks.ags.c;

import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.map.DynamicLayerInfo;
import com.esri.core.map.TimeExtent;
import com.esri.core.tasks.SpatialRelationship;
import com.esri.core.tasks.ags.query.OrderByFields;
import com.esri.core.tasks.ags.query.OutStatistics;
import com.esri.core.tasks.query.Order;
import com.esri.core.tasks.query.OutStatistics;
import com.esri.core.tasks.query.QueryParameters;
import com.github.mikephil.charting.utils.Utils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/* loaded from: classes.dex */
public class i extends com.esri.core.internal.tasks.f {
    private static final long serialVersionUID = 1;
    protected String a;
    String b;
    protected Geometry c;
    SpatialRelationship d;
    SpatialReference e;
    protected SpatialReference f;
    protected String[] h;
    protected long[] i;
    DynamicLayerInfo m;
    TimeExtent n;
    protected Map<String, Order> o;
    String[] p;
    OutStatistics[] q;
    protected boolean g = true;
    protected boolean j = false;
    double k = Utils.DOUBLE_EPSILON;
    protected int l = -1;
    boolean r = false;
    boolean s = false;
    String t = null;

    @Override // com.esri.core.internal.tasks.f
    public boolean validate() {
        return true;
    }

    public static i a(QueryParameters queryParameters) {
        if (queryParameters == null) {
            return null;
        }
        i iVar = new i();
        iVar.a(queryParameters.getWhere());
        iVar.b(queryParameters.getText());
        iVar.a(queryParameters.getGeometry());
        iVar.a(queryParameters.getSpatialRelationship());
        iVar.c(queryParameters.getInSpatialReference());
        iVar.b(queryParameters.getOutSpatialReference());
        iVar.a(queryParameters.isReturnGeometry());
        iVar.a(queryParameters.getOutFields());
        iVar.a(queryParameters.getObjectIds());
        iVar.b(queryParameters.isReturnIdsOnly());
        iVar.a(queryParameters.getMaxAllowableOffset());
        return iVar;
    }

    static final SpatialReference a(SpatialReference spatialReference) {
        if (spatialReference != null) {
            if (spatialReference.getID() >= 0) {
                return SpatialReference.create(spatialReference.getID());
            }
            if (spatialReference.getText() == null) {
                return spatialReference;
            }
            try {
                return SpatialReference.create(spatialReference.getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public int a() {
        return this.l;
    }

    public void a(int i) {
        this.l = i;
    }

    public DynamicLayerInfo b() {
        return this.m;
    }

    public void a(DynamicLayerInfo dynamicLayerInfo) {
        this.m = dynamicLayerInfo;
    }

    public boolean c() {
        return this.m != null;
    }

    public long[] d() {
        return this.i;
    }

    public void a(long[] jArr) {
        this.i = jArr;
    }

    public String e() {
        return this.a;
    }

    public i a(String str) {
        this.a = str;
        return this;
    }

    public String f() {
        return this.b;
    }

    public i b(String str) {
        this.b = str;
        return this;
    }

    public double g() {
        return this.k;
    }

    public void a(double d) {
        this.k = d;
    }

    public SpatialRelationship h() {
        return this.d;
    }

    public i a(SpatialRelationship spatialRelationship) {
        this.d = spatialRelationship;
        return this;
    }

    public SpatialReference i() {
        return this.e;
    }

    public i b(SpatialReference spatialReference) {
        this.e = spatialReference;
        return this;
    }

    public boolean j() {
        return this.g;
    }

    public i a(boolean z) {
        this.g = z;
        return this;
    }

    public boolean k() {
        return this.j;
    }

    public i b(boolean z) {
        this.j = z;
        return this;
    }

    public String[] l() {
        return this.h;
    }

    public i a(String[] strArr) {
        this.h = strArr;
        return this;
    }

    public SpatialReference m() {
        return this.f;
    }

    public void c(SpatialReference spatialReference) {
        this.f = spatialReference;
    }

    public TimeExtent n() {
        return this.n;
    }

    public void a(TimeExtent timeExtent) {
        this.n = timeExtent;
    }

    @Override // com.esri.core.internal.tasks.f
    public Map<String, String> generateRequestParams() {
        OutStatistics[] outStatisticsArr;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        if (c()) {
            try {
                linkedHashMap.put("layer", this.m.toJson());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (!com.esri.core.internal.util.a.a(this.b)) {
            linkedHashMap.put("text", this.b);
        }
        if (!com.esri.core.internal.util.a.a(this.a)) {
            linkedHashMap.put("where", this.a);
        }
        Geometry geometry = this.c;
        if (geometry != null) {
            try {
                linkedHashMap.put("geometry", GeometryEngine.geometryToJson(null, geometry));
                SpatialReference spatialReference = this.f;
                if (spatialReference != null) {
                    linkedHashMap.put("inSR", Integer.toString(spatialReference.getID()));
                }
                linkedHashMap.put("geometryType", com.esri.core.internal.util.d.a(this.c.getType()));
                SpatialRelationship spatialRelationship = this.d;
                if (spatialRelationship == null) {
                    spatialRelationship = SpatialRelationship.INTERSECTS;
                }
                linkedHashMap.put("spatialRel", spatialRelationship.getValue());
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        SpatialReference spatialReference2 = this.e;
        if (spatialReference2 != null) {
            linkedHashMap.put("outSR", String.valueOf(spatialReference2.getID()));
        }
        double d = this.k;
        if (d > Utils.DOUBLE_EPSILON) {
            linkedHashMap.put("maxAllowableOffset", Double.toString(d));
        }
        linkedHashMap.put("returnGeometry", Boolean.toString(this.g));
        linkedHashMap.put("returnIdsOnly", Boolean.toString(this.j));
        if (!com.esri.core.internal.util.a.a(this.h)) {
            linkedHashMap.put("outFields", com.esri.core.internal.util.a.a(this.h, ","));
        }
        if (!com.esri.core.internal.util.a.a(this.i)) {
            linkedHashMap.put("objectIds", com.esri.core.internal.util.a.a(this.i, ","));
        }
        TimeExtent timeExtent = this.n;
        if (timeExtent != null) {
            linkedHashMap.put("time", timeExtent.toString());
        }
        Map<String, Order> map = this.o;
        boolean z = true;
        if (map != null && !map.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            boolean z2 = true;
            for (String str : this.o.keySet()) {
                if (!com.esri.core.internal.util.a.a(str)) {
                    if (z2) {
                        z2 = false;
                    } else {
                        sb.append(',');
                    }
                    sb.append(str);
                    Order order = this.o.get(str);
                    if (order != null) {
                        sb.append(' ');
                        sb.append(order.toString().toLowerCase());
                    }
                }
            }
            if (sb.length() > 0) {
                linkedHashMap.put("orderByFields", sb.toString());
            }
        }
        if (!com.esri.core.internal.util.a.a(this.p)) {
            linkedHashMap.put("groupByFieldsForStatistics", com.esri.core.internal.util.a.a(this.p, ","));
        }
        if (!com.esri.core.internal.util.a.a(this.q)) {
            StringBuilder sb2 = new StringBuilder();
            sb2.append('[');
            for (OutStatistics outStatistics : this.q) {
                if (outStatistics != null && !outStatistics.isEmpty()) {
                    if (z) {
                        z = false;
                    } else {
                        sb2.append(',');
                    }
                    sb2.append(outStatistics.toJson());
                }
            }
            sb2.append(']');
            linkedHashMap.put("outStatistics", sb2.toString());
        }
        linkedHashMap.put("returnZ", Boolean.toString(this.r));
        linkedHashMap.put("returnM", Boolean.toString(this.s));
        String str2 = this.t;
        if (str2 != null) {
            linkedHashMap.put("gdbVersion", str2);
        }
        int i = this.l;
        if (i != -1) {
            linkedHashMap.put("maxFeatures", Integer.toString(i));
        }
        return linkedHashMap;
    }

    public String o() {
        OutStatistics[] outStatisticsArr;
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        if (!com.esri.core.internal.util.a.a(this.a)) {
            sb.append(",\"where\":\"" + this.a + "\"");
        }
        if (this.c != null) {
            try {
                sb.append(",\"geometry\":" + GeometryEngine.geometryToJson(null, this.c));
                if (this.f != null) {
                    sb.append(",\"inSR\":" + Integer.toString(this.f.getID()));
                }
                sb.append(",\"geometryType\":\"" + com.esri.core.internal.util.d.a(this.c.getType()) + "\"");
                StringBuilder sb2 = new StringBuilder();
                sb2.append(",\"spatialRel\":\"");
                SpatialRelationship spatialRelationship = this.d;
                if (spatialRelationship == null) {
                    spatialRelationship = SpatialRelationship.INTERSECTS;
                }
                sb2.append(spatialRelationship.getValue());
                sb2.append("\"");
                sb.append(sb2.toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (this.e != null) {
            sb.append(",\"outSR\":" + Integer.toString(this.e.getID()));
        }
        if (!this.g) {
            sb.append(",\"returnGeometry\":false");
        }
        if (this.j) {
            sb.append(",\"returnIdsOnly\":true");
        }
        if (this.l != -1) {
            sb.append(",\"maxFeatures\":" + this.l);
        }
        if (!com.esri.core.internal.util.a.a(this.h)) {
            sb.append(",\"outFields\":\"" + com.esri.core.internal.util.a.a(this.h, ",") + "\"");
        }
        if (!com.esri.core.internal.util.a.a(this.i)) {
            sb.append(",\"objectIds\":\"" + com.esri.core.internal.util.a.a(this.i, ",") + "\"");
        }
        Map<String, Order> map = this.o;
        if (map != null && !map.isEmpty()) {
            StringBuilder sb3 = new StringBuilder();
            boolean z = true;
            for (String str : this.o.keySet()) {
                if (!com.esri.core.internal.util.a.a(str)) {
                    if (z) {
                        z = false;
                    } else {
                        sb3.append(',');
                    }
                    sb3.append(str);
                    Order order = this.o.get(str);
                    if (order != null) {
                        sb3.append(' ');
                        sb3.append(order.toString().toLowerCase());
                    }
                }
            }
            if (sb3.length() > 0) {
                sb.append(",\"orderByFields\":\"" + sb3.toString() + "\"");
            }
        }
        if (!com.esri.core.internal.util.a.a(this.p)) {
            sb.append(",\"groupByFieldsForStatistics\":\"" + com.esri.core.internal.util.a.a(this.p, ",") + "\"");
        }
        if (!com.esri.core.internal.util.a.a(this.q)) {
            StringBuilder sb4 = new StringBuilder();
            sb4.append('[');
            boolean z2 = true;
            for (OutStatistics outStatistics : this.q) {
                if (outStatistics != null && !outStatistics.isEmpty()) {
                    if (z2) {
                        z2 = false;
                    } else {
                        sb4.append(',');
                    }
                    sb4.append(outStatistics.toJson());
                }
            }
            sb4.append(']');
            sb.append(",\"outStatistics\":" + sb4.toString());
        }
        sb.append("}");
        if (sb.length() > 2) {
            sb.delete(1, 2);
        }
        return sb.toString();
    }

    public Geometry p() {
        return this.c;
    }

    public void a(Geometry geometry) {
        this.c = geometry;
    }

    public Map<String, Order> q() {
        return this.o;
    }

    @Deprecated
    public Map<String, OrderByFields> r() {
        return d(this.o);
    }

    public void a(Map<String, Order> map) {
        this.o = map;
    }

    @Deprecated
    public void b(Map<String, OrderByFields> map) {
        this.o = c(map);
    }

    public String[] s() {
        return this.p;
    }

    public void b(String[] strArr) {
        this.p = strArr;
    }

    public OutStatistics[] t() {
        return this.q;
    }

    public void a(OutStatistics[] outStatisticsArr) {
        this.q = outStatisticsArr;
    }

    @Deprecated
    public void a(com.esri.core.tasks.ags.query.OutStatistics[] outStatisticsArr) {
        this.q = b(outStatisticsArr);
    }

    public boolean u() {
        return this.r;
    }

    public void c(boolean z) {
        this.r = z;
    }

    public boolean v() {
        return this.s;
    }

    public void d(boolean z) {
        this.s = z;
    }

    public String w() {
        return this.t;
    }

    public void c(String str) {
        this.t = str;
    }

    public int hashCode() {
        TimeExtent timeExtent = this.n;
        int hashCode = ((timeExtent == null ? 0 : timeExtent.hashCode()) + 31) * 31;
        DynamicLayerInfo dynamicLayerInfo = this.m;
        int hashCode2 = (hashCode + (dynamicLayerInfo == null ? 0 : dynamicLayerInfo.hashCode())) * 31;
        Geometry geometry = this.c;
        int hashCode3 = (((hashCode2 + (geometry == null ? 0 : geometry.hashCode())) * 31) + Arrays.hashCode(this.p)) * 31;
        SpatialReference spatialReference = this.f;
        int hashCode4 = hashCode3 + (spatialReference == null ? 0 : spatialReference.hashCode());
        long doubleToLongBits = Double.doubleToLongBits(this.k);
        int hashCode5 = ((((((hashCode4 * 31) + ((int) (doubleToLongBits ^ (doubleToLongBits >>> 32)))) * 31) + this.l) * 31) + Arrays.hashCode(this.i)) * 31;
        Map<String, Order> map = this.o;
        int hashCode6 = (((hashCode5 + (map == null ? 0 : map.hashCode())) * 31) + Arrays.hashCode(this.h)) * 31;
        SpatialReference spatialReference2 = this.e;
        int hashCode7 = (((((((hashCode6 + (spatialReference2 == null ? 0 : spatialReference2.hashCode())) * 31) + Arrays.hashCode(this.q)) * 31) + (this.g ? 1231 : 1237)) * 31) + (this.j ? 1231 : 1237)) * 31;
        SpatialRelationship spatialRelationship = this.d;
        int hashCode8 = (hashCode7 + (spatialRelationship == null ? 0 : spatialRelationship.hashCode())) * 31;
        String str = this.b;
        int hashCode9 = (hashCode8 + (str == null ? 0 : str.hashCode())) * 31;
        String str2 = this.a;
        return ((((hashCode9 + (str2 != null ? str2.hashCode() : 0)) * 31) + (this.r ? 1231 : 1237)) * 31) + (this.s ? 1231 : 1237);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj != null && getClass() == obj.getClass()) {
            i iVar = (i) obj;
            TimeExtent timeExtent = this.n;
            if (timeExtent == null) {
                if (iVar.n != null) {
                    return false;
                }
            } else if (!timeExtent.equals(iVar.n)) {
                return false;
            }
            DynamicLayerInfo dynamicLayerInfo = this.m;
            if (dynamicLayerInfo == null) {
                if (iVar.m != null) {
                    return false;
                }
            } else if (!dynamicLayerInfo.equals(iVar.m)) {
                return false;
            }
            Geometry geometry = this.c;
            if (geometry == null) {
                if (iVar.c != null) {
                    return false;
                }
            } else if (!geometry.equals(iVar.c)) {
                return false;
            }
            if (Arrays.equals(this.p, iVar.p)) {
                SpatialReference spatialReference = this.f;
                if (spatialReference == null) {
                    if (iVar.f != null) {
                        return false;
                    }
                } else if (!spatialReference.equals(iVar.f)) {
                    return false;
                }
                if (Double.doubleToLongBits(this.k) == Double.doubleToLongBits(iVar.k) && this.l == iVar.l && Arrays.equals(this.i, iVar.i)) {
                    Map<String, Order> map = this.o;
                    if (map == null) {
                        if (iVar.o != null) {
                            return false;
                        }
                    } else if (!map.equals(iVar.o)) {
                        return false;
                    }
                    if (Arrays.equals(this.h, iVar.h)) {
                        SpatialReference spatialReference2 = this.e;
                        if (spatialReference2 == null) {
                            if (iVar.e != null) {
                                return false;
                            }
                        } else if (!spatialReference2.equals(iVar.e)) {
                            return false;
                        }
                        if (Arrays.equals(this.q, iVar.q) && this.g == iVar.g && this.j == iVar.j && this.d == iVar.d) {
                            String str = this.b;
                            if (str == null) {
                                if (iVar.b != null) {
                                    return false;
                                }
                            } else if (!str.equals(iVar.b)) {
                                return false;
                            }
                            String str2 = this.a;
                            if (str2 == null) {
                                if (iVar.a != null) {
                                    return false;
                                }
                            } else if (!str2.equals(iVar.a)) {
                                return false;
                            }
                            return u() == iVar.r && v() == iVar.s;
                        }
                        return false;
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
        return false;
    }

    private Map<String, Order> c(Map<String, OrderByFields> map) {
        if (map == null) {
            return null;
        }
        HashMap hashMap = new HashMap();
        for (Map.Entry<String, OrderByFields> entry : map.entrySet()) {
            hashMap.put(entry.getKey(), entry.getValue() == OrderByFields.ASC ? Order.ASC : Order.DESC);
        }
        return hashMap;
    }

    private Map<String, OrderByFields> d(Map<String, Order> map) {
        if (map == null) {
            return null;
        }
        HashMap hashMap = new HashMap();
        for (Map.Entry<String, Order> entry : map.entrySet()) {
            hashMap.put(entry.getKey(), entry.getValue() == Order.ASC ? OrderByFields.ASC : OrderByFields.DESC);
        }
        return hashMap;
    }

    private OutStatistics[] b(com.esri.core.tasks.ags.query.OutStatistics[] outStatisticsArr) {
        if (outStatisticsArr == null) {
            return null;
        }
        OutStatistics[] outStatisticsArr2 = new OutStatistics[outStatisticsArr.length];
        int length = outStatisticsArr.length;
        int i = 0;
        int i2 = 0;
        while (i < length) {
            com.esri.core.tasks.ags.query.OutStatistics outStatistics = outStatisticsArr[i];
            outStatisticsArr2[i2] = new OutStatistics(a(outStatistics.getType()), outStatistics.getOnStatisticField(), outStatistics.getOutStatisticFieldName());
            i++;
            i2++;
        }
        return outStatisticsArr2;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.esri.core.internal.tasks.ags.c.i$1  reason: invalid class name */
    /* loaded from: classes.dex */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[OutStatistics.Type.values().length];
            a = iArr;
            try {
                iArr[OutStatistics.Type.AVG.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[OutStatistics.Type.COUNT.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[OutStatistics.Type.MAX.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                a[OutStatistics.Type.MIN.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                a[OutStatistics.Type.STDDEV.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                a[OutStatistics.Type.SUM.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                a[OutStatistics.Type.VAR.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    private OutStatistics.Type a(OutStatistics.Type type) {
        if (type == null) {
            return null;
        }
        switch (AnonymousClass1.a[type.ordinal()]) {
            case 1:
                return OutStatistics.Type.AVG;
            case 2:
                return OutStatistics.Type.COUNT;
            case 3:
                return OutStatistics.Type.MAX;
            case 4:
                return OutStatistics.Type.MIN;
            case 5:
                return OutStatistics.Type.STDDEV;
            case 6:
                return OutStatistics.Type.SUM;
            case 7:
                return OutStatistics.Type.VAR;
            default:
                return null;
        }
    }
}
